home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / EGAVGA.SWG / 0007_VGA MODE 12 Code.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  28.5 KB  |  1,048 lines

  1. (*
  2.  
  3.  
  4. Hi..
  5.  
  6. This Unit is made all by myself, And There may be some problems with it, If
  7. so please let me know..
  8.  
  9. All the routines that are present here come from one big unit that i have,
  10. so there could be something missing( but as i said, just let me know))
  11.  
  12. there are some thing You have to keep in Mind when you are using these
  13. routines, But i will go over them..
  14.  
  15. There are routines where the x coordinate isn't 640 but 80 (Like Text),
  16. I've done this because I use 8x8 Text. (I now know that it isn't very hard
  17. for me to change it so you can put a char on every x-coordinate, But i don't
  18. feel much like it at the moment, Maybe in a couple of days))
  19.  
  20. Oh Yeah, None of my routines check if the coordinates are correct..
  21.  
  22. Andre Jakobs
  23.   MicroBrain Technologies Inc.
  24.     The Netherlands
  25.  
  26.  
  27. Procedure Plot12h(x,y:word;Color:byte);
  28. {x        (0-639)
  29.  y        (0-479)
  30.  Color    (0-15)
  31.  Plots a pixel in [Color] at [x],[y]}
  32. Procedure HLine12h(x,y,Length:word;Color:byte);
  33. {x        (0-639)
  34.  y        (0-479)
  35.  Length   (0-639)(But can of course be larger, cause there is no checking)
  36.  Color    (0-15)
  37.  Draws a horizontal Line in [Color] at [x],[y]}
  38. Procedure VLine12h(x,y,Length:word;Color:byte);
  39. {x        (0-639)
  40.  y        (0-479)
  41.  Length   (0-479)
  42.  Color    (0-15)
  43.  Draws a vertical Line in [Color] at [x],[y]}
  44. Procedure Block12h(x,y,Width,Height:word;Color:byte);
  45. {x        (0-639)
  46.  y        (0-479)
  47.  Width    (0-639)
  48.  Height   (0-479)
  49.  Color    (0-15)
  50.  Draws a Box in [Color] at [x],[y] wich is [Width] Wide and [Height] High}
  51. Procedure Frame12h(x,y,Width,Height:word;Color:byte);
  52. {x        (0-639)
  53.  y        (0-479)
  54.  Width    (0-639)
  55.  Height   (0-479)
  56.  Color    (0-15)
  57.  Draws a Frame in [Color] at [x],[y] wich is [Width] Wide and [Height] High}
  58. Procedure PutChar12h(x,y:word;color:byte;cha:char);
  59. {x        (0-79)  !!!
  60.  y        (0-479)
  61.  Color    (0-15)
  62.  cha      ('Character')
  63.  Puts a character in [Color] at [x],[y]
  64.   Doesn't erase background, So if there already is a character use block to
  65.   erase it.
  66.   example:
  67.           Block(50 shl 3,100,8,8,1);
  68.                 ^^^^^^^^  (50 is the x coordinate that is used for the char
  69.                            but because block uses 0-639 and not (0-79) you
  70.                            have to multiply it by 8 (shl 3))
  71.           PutChar(50,100,7,'A');}
  72. Procedure PutString12h(x,y:word;Color:byte;Str:String);
  73. {x        (0-79)  !!!
  74.  y        (0-479)
  75.  Color    (0-15)
  76.  Str      ('String')
  77.  Puts a String in [Color] at [x],[y]
  78.   Doesn't erase background, So if there already is a String use block to
  79.   erase it.
  80.   example:
  81.           Block(50 shl 3,100,Length(String) shl 8,8,1);
  82.                 ^^^^^^^^  (50 is the x coordinate that is used for the char
  83.                            but because block uses 0-639 and not (0-79) you
  84.                            have to multiply it by 8 (shl 3))
  85.           PutString(50,100,7,'A');}
  86. Procedure Window12h(x,y,Width,Height:word;Color0,Color1,Color2:byte);
  87. {x        (0-79)  !!!
  88.  y        (0-479)
  89.  Width    (0-79)  !!!
  90.  Height   (0-479)
  91.  Color1   (0-15)    (Darkest Color)
  92.  Color2   (0-15)    (Window Main Color)
  93.  Color3   (0-15)    (Lightest Color)
  94.  Draws a Window at [x],[y] wich is [Width] Wide and [Height] High
  95.  example:
  96.          Window12h(9,89,39,79,8,7,15)
  97.  }
  98. Procedure CloseWindow12h;
  99. {closes Last opened Window, there is a max of 16 windows at the moment, But you
  100.  can increase it if you want}
  101. Procedure SaveScreen12h;
  102. {Saves a complete Mode 12h Screen}
  103. Procedure RestoreScreen12h;
  104. {Restores Screen that is saved using SaveScreen12h}
  105.  
  106. Procedure Mode12h;{640x480x16, write mode 2}
  107. {Sets Up mode 12h}
  108. Procedure Button(x,y,W,H:Word;Color0,Color1,Color2:byte);
  109. {x        (0-639)
  110.  y        (0-479)
  111.  Width    (0-639)
  112.  Height   (0-479)
  113.  Color1   (0-15)    (Darkest Color)
  114.  Color2   (0-15)    (Window Main Color)
  115.  Color3   (0-15)    (Lightest Color)
  116.  Draws a Button at [x],[y] wich is [Width] Wide and [Height] High
  117.  }
  118.  
  119. Procedure LoadFont;
  120. {This Loads a 8x8 Font into an array '_8x8P' that is used to display the text
  121.  You can optain this font by saving the 8x8 ROM font to a binary file and then
  122.  load it into this array.. (you can use a font util to save the font to disk
  123.  try some at (x2ftp.oulu.fi msdos/programming, and search for something that
  124.  has the name 2l8 (Too Late) font editor v1.20)},
  125.  Or you can load the _8x8Seg,_8x8Ofs with the Segment and Offset to the VGA 8x8
  126.  ROM Font..
  127.  
  128. Hope You can use these routines, Cause I use them alot now (Don't use textmode
  129. anymore, But this Mode)..
  130.  
  131. *)
  132. UNIT VGA_12h;
  133.  
  134. INTERFACE
  135. USES CRT,DOS;
  136. Type
  137.     PlotProc     =Procedure(x,y:word;Color:byte);
  138.     HLineProc    =Procedure(x,y,Length:word;Color:byte);
  139.     VLineProc    =Procedure(x,y,Length:word;Color:byte);
  140.     BlockProc    =Procedure(x,y,Width,Height:word;Color:byte);
  141.     FrameProc    =Procedure(x,y,Width,Height:word;Color:byte);
  142.     PutCharProc  =Procedure(x,y:word;color:byte;cha:char);
  143.     PutStringProc=Procedure(x,y:word;Color:byte;Str:String);
  144.  
  145. var
  146.    Result       : word;
  147.  
  148. {Procedures}
  149.    ClrScr       : Procedure;            {Clear Screen}
  150.    Plot         : PlotProc;             {Plot(x,y,Color)}
  151.    HLine        : HLineProc;            {HorizontalLine(x,y,Length,Color)}
  152.    VLine        : VLineProc;            {VerticalLine(x,y,Length,Color)}
  153.    Block        : BlockProc;            {Block(x,y,Width,Height,Color)}
  154.    Frame        : FrameProc;
  155.    PutChar      : PutCharProc;          {PutCharacter(x,y,Color,Char)}
  156.    PutString    : PutStringProc;        {PutString(x,y,Color,String)}
  157.    SaveScreen   : Procedure;            {SaveScreen}
  158.    RestoreScreen: Procedure;            {RestoreScreen}
  159.  
  160. {Mode 12h Routines}
  161. Procedure Plot12h(x,y:word;Color:byte);
  162. Procedure HLine12h(x,y,Length:word;Color:byte);
  163. Procedure VLine12h(x,y,Length:word;Color:byte);
  164. Procedure Block12h(x,y,Width,Height:word;Color:byte);
  165. Procedure Frame12h(x,y,Width,Height:word;Color:byte);
  166. Procedure PutChar12h(x,y:word;color:byte;cha:char);
  167. Procedure PutString12h(x,y:word;Color:byte;Str:String);
  168. Procedure Window12h(x,y,Width,Height:word;Color0,Color1,Color2:byte);
  169. Procedure CloseWindow12h;
  170. Procedure SaveScreen12h;
  171. Procedure RestoreScreen12h;
  172.  
  173. Procedure Mode12h;{640x480x16, write mode 2}
  174. Procedure Button(x,y,W,H:Word;Color0,Color1,Color2:byte);
  175.  
  176. IMPLEMENTATION
  177.  
  178. Type
  179.     Window12hType = record
  180.                       Width : byte;
  181.                       Height: word;
  182.                       VidOfs: word;
  183.                       Plane0: pointer;
  184.                       Plane1: pointer;
  185.                       Plane2: pointer;
  186.                       Plane3: pointer;
  187.                      end;
  188. Var
  189.    WindowList12h     : Array [1..16] of ^Window12hType;
  190.    LastWindow12h     : byte;
  191.    ScreenGrab        : Array [0..3] of pointer;
  192.    _8x8Seg,_8x8Ofs   : word;
  193.    _8x8P             : Array [0..2048] of byte;
  194.  
  195. {*****************************************************************
  196.                     GRAPHICS & TEXT ROUTINES
  197.  *****************************************************************}
  198. Procedure LoadFont;
  199. var
  200.    F    : file;
  201. begin
  202.   assign(F,'8x8');
  203.   reset(F,1);
  204.   blockread(f,_8x8P[0],2048);
  205.   close(F);
  206.   _8x8Seg:=Seg(_8x8P[0]);
  207.   _8x8Ofs:=Ofs(_8x8P[0]);
  208.  end;
  209.  
  210. Procedure Mode12h;{Assembler;{640x480x16}
  211. begin
  212.   @Plot:=@Plot12h;
  213.   @VLine:=@VLine12h;
  214.   @HLine:=@HLine12h;
  215.   @Block:=@Block12h;
  216.   @Frame:=@Frame12h;
  217.   @PutChar:=@PutChar12h;
  218.   @PutString:=@PutString12h;
  219.   @SaveScreen:=@SaveScreen12h;
  220.   @RestoreScreen:=@RestoreScreen12h;
  221.   Asm
  222.     Mov     AH,00
  223.     Mov     AL,12h
  224.     Int     10h
  225.     mov     dx,03ceh    {Graphics Controller}
  226.     mov     ax,0205h    {Mode Register, Write Mode 2}
  227.     out     dx,ax
  228.    end;
  229. end;
  230.  
  231. Procedure Button(x,y,W,H:Word;Color0,Color1,Color2:byte);
  232. begin
  233.   Block(x,y,W,H,Color1);
  234.   HLine(x+1,y,W-2,Color2);
  235.   VLine(x,y+1,H-2,Color2);
  236.   HLine(x+1,y+H-1,W-1,Color0);
  237.   VLine(x+W-1,y+1,H-1,Color0);
  238.  end;
  239.  
  240. Procedure ClrScr12h;assembler;
  241. asm
  242.   mov   es,SegA000
  243.   mov   di,00h
  244.   mov   ax,00h
  245.   mov   cx,19200
  246.   rep   stosw
  247.  end;
  248.  
  249. Procedure Plot12h(x,y:word;Color:byte); assembler;
  250. asm
  251.   mov   ax,SegA000      {Calculate Offset}
  252.   mov   es,ax
  253.   mov   bx,[y]
  254.   mov   di,bx
  255.   shl   di,6            {80*y}
  256.   shl   bx,4
  257.   add   di,bx
  258.  
  259.   mov   cx,[x]
  260.   mov   bx,cx
  261.   shr   bx,3            {/8}
  262.   add   di,bx           {80*y+ (x/8)}
  263.  
  264.   and   cx,7            {Get Bit that Changes}
  265.   mov   ah,128
  266.   shr   ah,cl
  267.   mov   dx,03ceh
  268.   mov   al,8
  269.   out   dx,ax
  270.   mov   dl,[es:di]
  271.   mov   al,[Color]
  272.   mov   [es:di],al
  273. end;
  274.  
  275. Procedure HLine12h(x,y,Length:word;Color:byte);Assembler;
  276. asm
  277.   mov   bx,[x]
  278.   mov   si,[Length]
  279.   or    si,si           {Check if Length=0}
  280.   jz    @D_End           {If So then jump to End}
  281.   mov   dx,03ceh        {Graphics Controller}
  282.  
  283.   mov   ax,SegA000      {Calculate Offset}
  284.   mov   es,ax
  285.   mov   ax,[y]
  286.   mov   di,ax
  287.   shl   di,6            {80*y}
  288.   shl   ax,4
  289.   add   di,ax
  290.  
  291.   mov   ax,bx
  292.   shr   ax,3            {/8}
  293.   add   di,ax           {80*y+ (x/8)}
  294.  
  295. {di = Offset in VMem}
  296. {Si = Length}
  297. {bx = x}
  298. {dx = Graphix Controller}
  299.  
  300. {ax = empty}
  301. {cx = empty}
  302.  
  303.   mov   cx,bx           {Get StartBit}
  304.   and   cx,07h
  305.  
  306.   mov   ax,si
  307.   add   ax,cx
  308.   cmp   ax,8            {Is x+Length<One Byte}
  309.   jb    @D_One
  310.  
  311.   mov   ah,0ffh         {11111111b}
  312.   shr   ah,cl           {BitMask}
  313.   mov   al,8            {BitMask Register}
  314.   out   dx,ax           {Write BitMask}
  315.   mov   al,[es:di]
  316.   mov   al,[Color]
  317.   mov   [es:di],al
  318.   inc   di
  319.  
  320.   mov   al,8            {BitMask Register}
  321.   mov   ah,0ffh         {BitMask}
  322.   out   dx,ax           {Write BitMask}
  323.  
  324.   mov   ax,si
  325.   mov   ch,8
  326.   sub   ch,cl
  327.   mov   cl,ch
  328.   xor   ch,ch
  329.   sub   ax,cx
  330.   shr   ax,3            {Length div 8}
  331.   mov   cx,ax
  332.   mov   al,[Color]
  333.   rep   stosb
  334.  
  335.   mov   cx,bx           {cx:=x+Length}
  336.   add   cx,si
  337.   and   cx,07h          {cx and 07}
  338.   mov   ah,0ffh
  339.   shr   ah,cl           {BitMask}
  340.   cmp   ah,0
  341.   je    @D_End
  342.  
  343.   not   ah
  344.   mov   al,8            {BitMask Register}
  345.   out   dx,ax           {Write BitMask}
  346.   mov   cl,[es:di]
  347.   mov   al,[Color]
  348.   mov   [es:di],al
  349.   jmp   @D_End
  350.  
  351. @D_One:
  352.   mov   ah,0ffh
  353.   shr   ah,cl           {Left BitMask}
  354.  
  355.   add   bx,si
  356.   dec   bx
  357.   and   bx,07h
  358.  
  359.   mov   cx,7
  360.   sub   cx,bx
  361.  
  362.   mov   bl,0ffh
  363.   shl   bl,cl          {Right BitMask}
  364.  
  365.   and   ah,bl          {Full  BitMask}
  366.   mov   al,8           {BitMask Register}
  367.   out   dx,ax          {Write BitMask}
  368.  
  369.   mov   dl,[es:di]     {Fill Latches}
  370.   mov   al,[Color]
  371.   mov   [es:di],al     {Write Pixel}
  372. @D_End:
  373.  end;
  374.  
  375. Procedure VLine12h(x,y,Length:word;Color:byte);Assembler;
  376. asm
  377.   mov   ax,SegA000      {Calculate Offset}
  378.   mov   es,ax
  379.   mov   bx,[y]
  380.   mov   di,bx
  381.   shl   di,6            {80*y}
  382.   shl   bx,4
  383.   add   di,bx
  384.  
  385.   mov   cx,[x]
  386.   mov   bx,cx
  387.   shr   bx,3            {/8}
  388.   add   di,bx           {80*y+ (x/8)}
  389.  
  390.   and   cx,7            {Get Bit that Changes}
  391.   mov   ah,80h
  392.   shr   ah,cl           {BitMask Value}
  393.   mov   dx,03ceh        {Graphics Controller}
  394.   mov   al,8            {BitMask Register}
  395.   out   dx,ax           {BitMask Setup}
  396.   mov   bx,[Length]
  397.   mov   al,[Color]
  398. @D_L:
  399.   mov   dl,[es:di]
  400.   mov   [es:di],al      {Put Byte at Offset}
  401.   add   di,80
  402.   dec   bx
  403.   jnz   @D_L
  404.  end;
  405.  
  406. Procedure Block12h(x,y,Width,Height:word;Color:byte);Assembler;
  407. asm
  408.   mov   bx,[x]
  409.   mov   si,[Width]
  410.   or    si,si           {Check if Length=0}
  411.   jz    @D_End           {If So then jump to End}
  412.  
  413.   mov   ax,SegA000      {Calculate Offset}
  414.   mov   es,ax
  415.   mov   ax,[y]
  416.   mov   di,ax
  417.   shl   di,6            {80*y}
  418.   shl   ax,4
  419.   add   di,ax
  420.  
  421.   mov   ax,bx
  422.   shr   ax,3            {/8}
  423.   add   di,ax           {80*y+ (x/8)}
  424.  
  425. {di = Offset in VMem}
  426. {Si = Length}
  427. {bx = x}
  428. {dx = Graphix Controller}
  429.  
  430. {ax = empty}
  431. {cx = empty}
  432.  
  433.   mov   cx,bx           {Get StartBit}
  434.   and   cx,07h
  435.  
  436.   mov   ax,si
  437.   add   ax,cx
  438.   cmp   ax,8            {Is x+Length<One Byte}
  439.   jb    @D_One
  440.  
  441.   mov   ah,0ffh         {11111111b}
  442.   shr   ah,cl           {BitMask}
  443.   mov   al,8            {BitMask Register}
  444.   mov   dx,03ceh        {Graphics Controller}
  445.   out   dx,ax           {Write BitMask}
  446.   push  cx
  447.   mov   ah,[Color]
  448.   mov   cx,[Height]
  449.   mov   dx,di
  450. @D_LL:                   {Draw Left of Box}
  451.   mov   al,[es:di]
  452.   mov   [es:di],ah
  453.   add   di,80           {di:=di+80}
  454.   dec   cx
  455.   jnz   @D_LL
  456.   mov   di,dx
  457.   inc   di
  458.   pop   cx
  459.  
  460.   mov   al,8            {BitMask Register}
  461.   mov   ah,0ffh         {BitMask}
  462.   mov   dx,03ceh        {Graphics Controller}
  463.   out   dx,ax           {Write BitMask}
  464.  
  465.   mov   ax,si
  466.   mov   ch,8
  467.   sub   ch,cl
  468.   mov   cl,ch
  469.   xor   ch,ch
  470.   sub   ax,cx
  471.   shr   ax,3            {Length div 8}
  472.  
  473.   push  di
  474.   push  bx
  475.   mov   bx,[Height]
  476.   mov   dx,ax
  477.   mov   al,[Color]
  478. @D_LC:
  479.   mov   cx,dx
  480.   rep   stosb
  481.   add   di,80
  482.   sub   di,dx
  483.   dec   bx
  484.   jnz   @D_LC
  485.   pop   bx
  486.   pop   di
  487.   add   di,dx
  488.  
  489.   mov   cx,bx           {cx:=x+Length}
  490.   add   cx,si
  491.   and   cx,07h          {cx and 07}
  492.   mov   ah,0ffh
  493.   shr   ah,cl           {BitMask}
  494.   cmp   ah,0
  495.   je    @D_End
  496.  
  497.   not   ah
  498.   mov   al,8            {BitMask Register}
  499.   mov   dx,03ceh        {Graphics Controller}
  500.   out   dx,ax           {Write BitMask}
  501.   mov   cx,[Height]
  502.   mov   al,[Color]
  503. @D_LR:
  504.   mov   ah,[es:di]
  505.   mov   [es:di],al
  506.   add   di,80
  507.   dec   cx
  508.   jnz   @D_LR
  509.  
  510.   jmp   @D_End
  511.  
  512. @D_One:
  513.   mov   ah,0ffh
  514.   shr   ah,cl           {Left BitMask}
  515.  
  516.   add   bx,si
  517.   dec   bx
  518.   and   bx,07h
  519.  
  520.   mov   cx,7
  521.   sub   cx,bx
  522.  
  523.   mov   bl,0ffh
  524.   shl   bl,cl          {Right BitMask}
  525.  
  526.   and   ah,bl          {Full  BitMask}
  527.   mov   al,8           {BitMask Register}
  528.   mov   dx,03ceh        {Graphics Controller}
  529.   out   dx,ax          {Write BitMask}
  530.   mov   cx,[Height]
  531.   mov   al,[Color]
  532. @D_L:
  533.   mov   dl,[es:di]     {Fill Latches}
  534.   mov   [es:di],al     {Write Pixel}
  535.   add   di,80
  536.   dec   cx
  537.   jnz   @D_L
  538. @D_End:
  539.  end;
  540.  
  541. Procedure Frame12h(x,y,Width,Height:word;Color:byte);
  542. begin
  543.   HLine(x,y,Width,Color);
  544.   VLine(x,y,Height,Color);
  545.   VLine(x+Width-1,y,Height,Color);
  546.   HLine(x,y+Height-1,Width,Color);
  547.  end;
  548.  
  549. Procedure PutChar12h(x,y:word;Color:byte;cha:char);Assembler;
  550. asm
  551.   push  ds
  552.   xor   bx,bx
  553.   mov   bl,[cha]
  554.   shl   bx,3
  555.   mov   ax,_8x8Seg
  556.   mov   ds,ax
  557.   mov   si,_8x8Ofs
  558.   add   si,bx
  559.  
  560.   mov   ax,SegA000      {Calculate Offset}
  561.   mov   es,ax
  562.   mov   di,[y]
  563.   mov   ax,di
  564.   shl   ax,6
  565.   shl   di,4
  566.   add   di,ax
  567.   add   di,[x]
  568.   mov   cx,8
  569.   mov   dx,03ceh
  570.   mov   al,8
  571.   mov   bl,[Color]
  572. @D_L:
  573.   mov   ah,[ds:si]
  574.   out   dx,ax
  575.   mov   ah,[es:di]
  576.   mov   [es:di],bl
  577.   inc   si
  578.   add   di,80
  579.   dec   cx
  580.   jnz   @D_L
  581.   pop   ds
  582. end;
  583.  
  584. Procedure PutString12h(x,y:word;Color:byte;Str:String);
  585. var
  586.    f1   : byte;
  587.    Cha  : char;
  588. begin
  589. for f1:=1 to ord(Str[0]) do
  590.  begin
  591.    cha:=Str[f1];
  592.    asm
  593.      push  ds
  594.      mov   ax,_8x8Seg
  595.      mov   ds,ax
  596.      mov   si,_8x8Ofs
  597.      xor   ax,ax
  598.      mov   al,cha
  599.      shl   ax,3
  600.      add   si,ax
  601.  
  602.      mov   ax,SegA000      {Calculate Offset}
  603.      mov   es,ax
  604.      mov   di,[y]
  605.      mov   ax,di
  606.      shl   ax,6
  607.      shl   di,4
  608.      add   di,ax
  609.      add   di,[x]
  610.      mov   cx,8
  611.      mov   dx,03ceh
  612.      mov   al,8
  613.      mov   bl,[Color]
  614. @D_L:
  615.      mov   ah,[ds:si]
  616.      out   dx,ax
  617.      mov   ah,[es:di]
  618.      mov   [es:di],bl
  619.      inc   si
  620.      add   di,80
  621.      dec   cx
  622.      jnz   @D_L
  623.      pop   ds
  624.     end;
  625.     inc(x);
  626.   end;{For}
  627. end;
  628.  
  629. Procedure Window12h(x,y,Width,Height:word;Color0,Color1,Color2:byte);
  630. var
  631.    VidOfs       : word;
  632.    ImOfs,ImSeg  : word;
  633.    ScrW         : word;
  634.    O0,S0,O1,S1  : word;
  635.    O2,S2,O3,S3  : word;
  636. begin
  637.   if LastWindow12h<16 then
  638.     begin
  639.       inc(LastWindow12h);
  640.       new(WindowList12h[LastWindow12h]);
  641.       VidOfs:=(y shl 6)+(y shl 4)+x;
  642.       WindowList12h[LastWindow12h]^.VidOfs:=VidOfs;
  643.       WindowList12h[LastWindow12h]^.Width :=Width;
  644.       WindowList12h[LastWindow12h]^.Height:=Height;
  645.       ScrW:=Width*Height;
  646.       GetMem(WindowList12h[LastWindow12h]^.Plane0,ScrW);
  647.       GetMem(WindowList12h[LastWindow12h]^.Plane1,ScrW);
  648.       GetMem(WindowList12h[LastWindow12h]^.Plane2,ScrW);
  649.       GetMem(WindowList12h[LastWindow12h]^.Plane3,ScrW);
  650.       S0:=Seg(WindowList12h[LastWindow12h]^.Plane0^);
  651.       O0:=Ofs(WindowList12h[LastWindow12h]^.Plane0^);
  652.       S1:=Seg(WindowList12h[LastWindow12h]^.Plane1^);
  653.       O1:=Ofs(WindowList12h[LastWindow12h]^.Plane1^);
  654.       S2:=Seg(WindowList12h[LastWindow12h]^.Plane2^);
  655.       O2:=Ofs(WindowList12h[LastWindow12h]^.Plane2^);
  656.       S3:=Seg(WindowList12h[LastWindow12h]^.Plane3^);
  657.       O3:=Ofs(WindowList12h[LastWindow12h]^.Plane3^);
  658.       ScrW:=80-Width;
  659.       asm
  660.         push  ds
  661.  
  662.         mov   bx,[Width]
  663.         mov   cx,[Height]
  664.  
  665.         mov   si,[VidOfs]
  666.         mov   ds,SegA000                 {ds:si VideoMem}
  667.         mov   dx,03ceh                   {Graphics Controller}
  668.         mov   ax,0005h                   {Mode Register, Write 0, Read  0}
  669.         out   dx,ax
  670.  
  671.  
  672.         mov   di,[O3]                    {Read Plane 3}
  673.         mov   es,[S3]                    {es:di ImageOfset}
  674.         mov   ax,0304h                   {Read Plane Select}
  675.         out   dx,ax
  676.         push  si                         {Save 'Start Window in VideoMem'}
  677.         push  cx
  678.         mov   ax,cx                      {cx=Height}
  679.     @B3:
  680.         mov   cx,bx                      {bx=Width}
  681.         rep   movsb                      {Read 8 Pixels}
  682.         add   si,[ScrW]                  {Goto Next Line by adding ScrWidth}
  683.         dec   ax
  684.         jnz   @B3
  685.         pop   cx
  686.         pop   si                         {Restore 'Start Window in VideoMem'}
  687.  
  688.         mov   di,[O2]                    {Read Plane 2}
  689.         mov   es,[S2]                    {es:di ImageOfset}
  690.         mov   ax,0204h                   {Read Plane Select}
  691.         out   dx,ax
  692.         push  si                         {Save 'Start Window in VideoMem'}
  693.         push  cx
  694.         mov   ax,cx                      {cx=Height}
  695.     @B2:
  696.         mov   cx,bx                      {bx=Width}
  697.         rep   movsb                      {Read 8 Pixels}
  698.         add   si,[ScrW]                  {Goto Next Line by adding ScrWidth}
  699.         dec   ax
  700.         jnz   @B2
  701.         pop   cx
  702.         pop   si                         {Restore 'Start Window in VideoMem'}
  703.  
  704.  
  705.         mov   di,[O1]                    {Read Plane 1}
  706.         mov   es,[S1]                    {es:di ImageOfset}
  707.         mov   ax,0104h                   {Read Plane Select}
  708.         out   dx,ax
  709.         push  si                         {Save 'Start Window in VideoMem'}
  710.         push  cx
  711.         mov   ax,cx                      {cx=Height}
  712.     @B1:
  713.         mov   cx,bx                      {bx=Width}
  714.         rep   movsb                      {Read 8 Pixels}
  715.         add   si,[ScrW]                  {Goto Next Line by adding ScrWidth}
  716.         dec   ax
  717.         jnz   @B1
  718.         pop   cx
  719.         pop   si                         {Restore 'Start Window in VideoMem'}
  720.  
  721.  
  722.         mov   di,[O0]                    {Read Plane 0}
  723.         mov   es,[S0]                    {es:di ImageOfset}
  724.         mov   ax,0004h                   {Read Plane Select}
  725.         out   dx,ax
  726.         mov   ax,cx                      {cx=Height}
  727.     @B0:
  728.         mov   cx,bx                      {bx=Width}
  729.         rep   movsb                      {Read 8 Pixels}
  730.         add   si,[ScrW]                  {Goto Next Line by adding ScrWidth}
  731.         dec   ax
  732.         jnz   @B0
  733.  
  734.         mov   ax,0205h                   {Mode Register, Write Mode 2}
  735.         out   dx,ax
  736.         pop   ds
  737.        end;
  738.      Width:=Width shl 3;
  739.      x:=x shl 3;
  740.      Block(x,y,Width,Height,Color1);
  741.      HLine(x+1,y,Width-2,Color2);
  742.      VLine(x,y+1,Height-2,Color2);
  743.      HLine(x+1,y+Height-1,Width-1,Color0);
  744.      VLine(x+width-1,y+1,Height-1,Color0);
  745.     end;
  746. end;
  747.  
  748. Procedure CloseWindow12h;
  749. var
  750.   Width,Height  : word;
  751.   SegWin,OfsWin : word;
  752.   OfsVid        : word;
  753.   ScrW          : word;
  754.   O0,S0,O1,S1   : word;
  755.   O2,S2,O3,S3   : word;
  756. begin
  757.   if LastWindow12h>0 then
  758.    begin
  759.      Width:=WindowList12h[LastWindow12h]^.Width;
  760.      Height:=WindowList12h[LastWindow12h]^.Height;
  761.      OfsVid:=WindowList12h[LastWindow12h]^.VidOfs;
  762.  
  763.      S0:=Seg(WindowList12h[LastWindow12h]^.Plane0^);
  764.      O0:=Ofs(WindowList12h[LastWindow12h]^.Plane0^);
  765.      S1:=Seg(WindowList12h[LastWindow12h]^.Plane1^);
  766.      O1:=Ofs(WindowList12h[LastWindow12h]^.Plane1^);
  767.      S2:=Seg(WindowList12h[LastWindow12h]^.Plane2^);
  768.      O2:=Ofs(WindowList12h[LastWindow12h]^.Plane2^);
  769.      S3:=Seg(WindowList12h[LastWindow12h]^.Plane3^);
  770.      O3:=Ofs(WindowList12h[LastWindow12h]^.Plane3^);
  771.      ScrW:=80-Width;
  772.      Asm
  773.        push ds
  774.       {GET OFFSET IN VIDEOMEM/MOUSEBACKUP}
  775.  
  776.        mov  bx,[Width]
  777.        mov  cx,[Height]
  778.        mov  es,SegA000
  779.        mov  di,[OfsVid]                {es:di Start in VideoMem}
  780.        mov  dx,03ceh                   {Graphics Controller}
  781.        mov  ax,0805h                   {Mode Register, Write Mode 0, Read Mode 
  782. 1}
  783.        out  dx,ax
  784.        mov  ax,0007h                   {color don't care Register}
  785.        out  dx,ax
  786.        mov  ax,0ff08h                  {BitMask Register}
  787.        out  dx,ax
  788.        mov  dx,03c4h                   {Sequencer Controller}
  789.  
  790.        cli
  791.        mov  si,[O3]
  792.        mov  ds,[S3]                    {ds:si Start in Memory}
  793.        mov  ax,0802h                   {Write Plane Select,Plane 3}
  794.        out  dx,ax                      {Write Read Plane Select}
  795.        push di                         {Save 'Start Window in VideoMem'}
  796.        mov  ax,[Height]                {Height}
  797.    @R3:
  798.        mov  cx,bx                      {bx=Width}
  799.        rep  movsb                      {Draw 8 Pixels}
  800.        add  di,[ScrW]                  {Goto Next Line by adding ScrWidth}
  801.        dec  ax
  802.        jnz  @R3
  803.        pop  di                         {Restore 'Start Window in VideoMem'}
  804.  
  805.  
  806.        mov  si,[O2]
  807.        mov  ds,[S2]                    {ds:si Start in Memory}
  808.        mov  ax,0402h                   {Write Plane Select,Plane 2}
  809.        out  dx,ax                      {Write Read Plane Select}
  810.        push di                         {Save 'Start Window in VideoMem'}
  811.        mov  ax,[Height]                {Height}
  812.    @R2:
  813.        mov  cx,bx                      {bx=Width}
  814.        rep  movsb                      {Draw 8 Pixels}
  815.        add  di,[ScrW]                  {Goto Next Line by adding ScrWidth}
  816.        dec  ax
  817.        jnz  @R2
  818.        pop  di                         {Restore 'Start Window in VideoMem'}
  819.  
  820.        mov  si,[O1]
  821.        mov  ds,[S1]                    {ds:si Start in Memory}
  822.        mov  ax,0202h                   {Write Plane Select,Plane 1}
  823.        out  dx,ax                      {Write Read Plane Select}
  824.        push di                         {Save 'Start Window in VideoMem'}
  825.        mov  ax,[Height]                {Height}
  826.    @R1:
  827.        mov  cx,bx                      {bx=Width}
  828.        rep  movsb                      {Draw 8 Pixels}
  829.        add  di,[ScrW]                  {Goto Next Line by adding ScrWidth}
  830.        dec  ax
  831.        jnz  @R1
  832.        pop  di                         {Restore 'Start Window in VideoMem'}
  833.  
  834.        mov  si,[O0]
  835.        mov  ds,[S0]                    {ds:si Start in Memory}
  836.        mov  ax,0102h                   {Write Plane Select,Plane 2}
  837.        out  dx,ax                      {Write Read Plane Select}
  838.        mov  ax,[Height]                {Height}
  839.    @R0:
  840.        mov  cx,bx                      {bx=Width}
  841.        rep  movsb                      {Draw 8 Pixels}
  842.        add  di,[ScrW]                  {Goto Next Line by adding ScrWidth}
  843.        dec  ax
  844.        jnz  @R0
  845.  
  846.        mov  ax,0f02h                   {Set All Planes to write}
  847.        out  dx,ax
  848.  
  849.        mov  dx,03ceh                   {Graphics Controller}
  850.        mov  ax,0205h                   {Mode Register, Write Mode 2}
  851.        out  dx,ax
  852.        sti
  853.        pop  ds
  854.       end;
  855.      ScrW:=Width*Height;
  856.      FreeMem(WindowList12h[LastWindow12h]^.Plane0,ScrW);
  857.      FreeMem(WindowList12h[LastWindow12h]^.Plane1,ScrW);
  858.      FreeMem(WindowList12h[LastWindow12h]^.Plane2,ScrW);
  859.      FreeMem(WindowList12h[LastWindow12h]^.Plane3,ScrW);
  860.      Dispose(WindowList12h[LastWindow12h]);
  861.      dec(LastWindow12h);
  862.     end;
  863. end;
  864.  
  865. Procedure SaveScreen12h;
  866. var
  867.    O0,S0,O1,S1  : word;
  868.    O2,S2,O3,S3  : word;
  869. begin
  870.   GetMem(ScreenGrab[0],38592);{80*480+64*3(Palet)}
  871.   GetMem(ScreenGrab[1],38400);{80*480}
  872.   GetMem(ScreenGrab[2],38400);{80*480}
  873.   GetMem(ScreenGrab[3],38400);{80*480}
  874.  
  875.   S0:=Seg(ScreenGrab[0]^);
  876.   O0:=Ofs(ScreenGrab[0]^);
  877.  
  878.   S1:=Seg(ScreenGrab[1]^);
  879.   O1:=Ofs(ScreenGrab[1]^);
  880.  
  881.   S2:=Seg(ScreenGrab[2]^);
  882.   O2:=Ofs(ScreenGrab[2]^);
  883.  
  884.   S3:=Seg(ScreenGrab[3]^);
  885.   O3:=Ofs(ScreenGrab[3]^);
  886.   asm
  887.     push ds
  888.  
  889.     mov  di,[O3]
  890.     mov  es,[S3]
  891.    {es:di          ImageOfset}
  892.     mov  ds,SegA000
  893.     xor  si,si
  894.    {ds:si          VideoMem}
  895.     mov  dx,03ceh                   {Graphics Controller}
  896.     mov  ax,0005h                   {Mode Register, Write 0, Read  0}
  897.     out  dx,ax
  898.     mov  ax,0304h                   {Read Plane Select}{Plane 3}
  899.     out  dx,ax
  900.     mov  cx,19200
  901.     rep  movsw
  902.  
  903.     mov  es,[S2]
  904.     mov  di,[O2]
  905.     xor  si,si
  906.     dec  ah                         {Plane 2}
  907.     out  dx,ax
  908.     mov  cx,19200
  909.     rep  movsw
  910.  
  911.     mov  es,[S1]
  912.     mov  di,[O1]
  913.     xor  si,si
  914.     dec  ah                         {Plane 1}
  915.     out  dx,ax
  916.     mov  cx,19200
  917.     rep  movsw
  918.  
  919.     mov  es,[S0]
  920.     mov  di,[O0]
  921.     xor  si,si
  922.     dec  ah                         {Plane 0}
  923.     out  dx,ax
  924.     mov  cx,19200
  925.     rep  movsw
  926.  
  927.     mov  dx,03ceh                   {Graphics Controller}
  928.     mov  ax,0205h                   {Mode Register, Write Mode 2}
  929.     out  dx,ax
  930.  
  931.     mov  dx,03c7h                   {Save Palette behind Plane 0}
  932.     mov  al,0
  933.     out  dx,al
  934.     mov  dx,03c9h
  935.     mov  cx,192                     {64 Colors RxGxB starting}
  936.     rep  insb
  937.     pop  ds
  938.    end;
  939.  end;
  940.  
  941. Procedure RestoreScreen12h;
  942. var
  943.    O0,S0,O1,S1  : word;
  944.    O2,S2,O3,S3  : word;
  945. Label
  946.      C1,C2,rt1,rt2;
  947. begin
  948.   S0:=Seg(ScreenGrab[0]^);
  949.   O0:=Ofs(ScreenGrab[0]^);
  950.  
  951.   S1:=Seg(ScreenGrab[1]^);
  952.   O1:=Ofs(ScreenGrab[1]^);
  953.  
  954.   S2:=Seg(ScreenGrab[2]^);
  955.   O2:=Ofs(ScreenGrab[2]^);
  956.  
  957.   S3:=Seg(ScreenGrab[3]^);
  958.   O3:=Ofs(ScreenGrab[3]^);
  959.   Asm
  960.     push ds
  961.  
  962.     mov   dx,03c8h
  963.     mov   al,0
  964.     out   dx,al
  965.     inc   dx
  966.     mov   cx,192
  967.   C1:
  968.     out   dx,al
  969.     dec   cx
  970.     jnz   C1
  971.  
  972.     mov  dx,03ceh                   {Graphics Controller}
  973.     mov  ax,0805h                   {Mode Register, Write Mode 0, Read Mode 1}
  974.     out  dx,ax
  975.     mov  ax,0007h                   {color don't care Register}
  976.     out  dx,ax
  977.     mov  ax,0ff08h                  {BitMask Register}
  978.     out  dx,ax
  979.     mov  dx,03c4h                   {Sequencer Controller}
  980.    {GET OFFSET IN VIDEOMEM}
  981.     mov  es,SegA000
  982.     xor  di,di
  983.    {es:di                Start in VideoMem}
  984.     mov  si,[O3]
  985.     mov  ds,[S3]
  986.    {ds:si                Start in Memory}
  987.     mov  ax,0802h                     {Write Plane Select}
  988.     out  dx,ax
  989.     cli
  990.     mov  cx,19200
  991.     rep  movsw
  992.  
  993.     xor  di,di
  994.    {es:di                Start in VideoMem}
  995.     mov  si,[O2]
  996.     mov  ds,[S2]
  997.    {ds:si                Start in Memory}
  998.     mov  ax,0402h                     {Write Plane Select}
  999.     out  dx,ax
  1000.     mov  cx,19200
  1001.     rep  movsw
  1002.  
  1003.     xor  di,di
  1004.    {es:di                Start in VideoMem}
  1005.     mov  si,[O1]
  1006.     mov  ds,[S1]
  1007.    {ds:si                Start in Memory}
  1008.     mov  ax,0202h                     {Write Plane Select}
  1009.     out  dx,ax
  1010.     mov  cx,19200
  1011.     rep  movsw
  1012.  
  1013.     xor  di,di
  1014.    {es:di                Start in VideoMem}
  1015.     mov  si,[O0]
  1016.     mov  ds,[S0]
  1017.    {ds:si                Start in Memory}
  1018.     mov  ax,0102h                     {Write Plane Select}
  1019.     out  dx,ax
  1020.     mov  cx,19200
  1021.     rep  movsw
  1022.     sti
  1023.     mov  ax,0f02h                  {Set All Planes to write}
  1024.     out  dx,ax
  1025.  
  1026.     mov  dx,03ceh                  {Graphics Controller}
  1027.     mov  ax,0205h                  {Mode Register, Write Mode 2}
  1028.     out  dx,ax
  1029.  
  1030.     mov   dx,03c8h
  1031.     mov   al,0
  1032.     out   dx,al
  1033.     inc   dx
  1034.     mov   cx,192
  1035.     rep   outsb
  1036.     pop  ds
  1037.    end;
  1038.   FreeMem(ScreenGrab[3],38400);{80*480}
  1039.   FreeMem(ScreenGrab[2],38400);{80*480}
  1040.   FreeMem(ScreenGrab[1],38400);{80*480}
  1041.   FreeMem(ScreenGrab[0],38592);{80*480+64*3}
  1042.  end;
  1043.  
  1044. begin
  1045.   LastWindow12h:=0;
  1046.   LoadFont;
  1047.  end.
  1048.